//
//  SettingsView.swift
//  HisPaste
//
//  Created by 烟雀 on 2024/2/17.
//

import Foundation
import SwiftUI

let tipMsg = """
提示:

1. 使用快捷键 "Command + J" 打开剪切板历史
2. 单击条目替换当前剪切板
3. 条目右侧可清理
4. 暂只支持字符串剪切板

"""

struct SettingsView: View{
    
    @State
    private var _startAtLogin = AppHelper.isEnabledAutoLaunch
    
    var body: some View{
        VStack(alignment: .leading, spacing: 0){
            
            Text("HisPaste")
                .font(Font.system(size: 15.0))
                .fontWeight(.semibold)
                .multilineTextAlignment(.leading)
                .padding(.horizontal, 15.0)
                .padding(.top, 15.0)
                .padding(.bottom, 15.0)
            
            Divider()
                .padding(.horizontal, 10.0)
                .frame(width: 300)

            Toggle(isOn: $_startAtLogin){
                Text("登陆时启动")
                    .fontWeight(.medium)
                    .padding(.top, 5.0)
                    .frame(width: 200, alignment: .leading)
            }
                .padding()
                .onChange(of: _startAtLogin, initial: false) { (oldValue, newValue) in
                    if newValue {
                        AppHelper.enableAutoLaunch()
                    } else {
                        AppHelper.disableAutoLaunch()
                    }
                    // _startAtLogin = newValue
                }
            
            Divider()
                .padding(.horizontal, 10.0)
                .frame(width: 300)
            
            Text(tipMsg)
                .padding(.all, 15.0)
                .font(Font.system(size: 11.0))
                .fontWeight(.thin)
                
            Divider()
                .padding(.horizontal, 10.0)
                .frame(width: 300)
            
        }
        
        HStack {
            Spacer()
            Button(action: {
                AppHelper.exit_()
            }, label: {
                Text("退出")
                    // .foregroundColor(.yellow)
            })
            .padding(.top, 15.0)
            .padding(.bottom, 10.0)
            .padding(.trailing, 10.0)
            .cornerRadius(100)
            .frame(width: 120, alignment: .trailing)
        }
        
        
    }
}
